package com.csd.action.team;

import java.io.File;

import com.csd.helper.ActionResult;
import com.csd.helper.Stage;
import com.csd.pojo.Project;
import com.csd.serviceImpl.DocumentRecordService;
import com.csd.serviceImpl.ProjectService;


/**
 * 
 * Action：申请一个工程／创建一个工程
 * @author csd
 * @version 1.0
 * 
 * <br> 修订时间：2009-12-17
 * <br> 修改原因：创建文件
 * <br> 修改人：刘世彬
 * <br> 
 * 
 */
public class ProjectCreateAction {
	/** 新工程 */
	private Project newProject;
	/** 工程申请的文档名称　*/
	private String uploadFileName;
	
	public File upload;

	private DocumentRecordService documentRecordService;

	private ProjectService service;

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public DocumentRecordService getDocumentRecordService() {
		return documentRecordService;
	}

	public void setDocumentRecordService(DocumentRecordService documentRecordService) {
		this.documentRecordService = documentRecordService;
	}

	

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public ProjectService getService() {
		return service;
	}

	public void setService(ProjectService service) {
		this.service = service;
	}



	public Project getNewProject() {
		return newProject;
	}

	public void setNewProject(Project newProject) {
		this.newProject = newProject;
	}

	public String execute() {
		String result = ActionResult.fail;
		//默认文件后缀名为.tmp
		String suffix = ".tmp";
		if(uploadFileName != null)
		{
		   suffix = this.uploadFileName.substring(this.uploadFileName.lastIndexOf('.'));
		}
		if(service.saveProject(this.newProject)&&documentRecordService.uploadDocument(upload, suffix, "applyDocument"));
			result = ActionResult.success;
		
		return result;
	}
}
